@extends('admin.layouts.default')
@section('content')
    <form action="{{route('admin.role.permission',$role)}}" method="post">
        @csrf
        <h3 class="card-title">编辑"<em>{{$role['title']}}</em>"角色的权限</h3>
        @foreach($modules as $module)
            {{--再加上一个判断,如果模块儿中有权限配置数据就展示出来,否则就不展示--}}
        @if($module['permission'])
        <div class="card">
            <div class="card-header">
                {{$module['name']}}
            </div>
            <div class="card-body">
                <div class="row">
                    @foreach($module['permission'] as $permission)
                    <div class="col-4">
                        {{--在这里需要判断这个角色之前有没有某个权限,如果有的话就选中,没有的话就不选中--}}
                        @if($role->hasPermissionTo($permission['name']))
                            <input type="checkbox" checked name="permission[]" value="{{$permission['name']}}">
                            @else
                            <input type="checkbox" name="permission[]" value="{{$permission['name']}}">
                        @endif
                        {{$permission['title']}}({{$permission['name']}})
                    </div>
                    @endforeach
                </div>
            </div>
        </div>
            @endif
        @endforeach
        <div class="card-footer text-muted">
            <button class="btn btn-sm btn-primary">保存</button>
        </div>
    </form>
@endsection